//
//  ChivoxLogTest.m
//  ChivoxEngineTests
//
//  Created by chivox on 2018/9/29.
//  Copyright © 2018 Chivox. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "ChivoxLog.h"

@interface ChivoxLogTest : XCTestCase

@end

@implementation ChivoxLogTest

- (void)setUp {
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
}

- (void)testPerformanceExample {
    // This is an example of a performance test case.
    [self measureBlock:^{
        // Put the code you want to measure the time of here.
    }];
}

- (void)testLogLevel {
    NSLog(@"==== testLogLevel ========");
    NSArray *levelArray = @[@"undefined", @"error", @"warn", @"notice", @"info", @"debug"];
    for (NSString *level in levelArray) {
        NSLog(@"==== level: %@", level);
        ChivoxLogInit(level);
        ChivoxLogError(@"show error at %@.", level);
        ChivoxLogWarn(@"show warn at %@.", level);
        ChivoxLogNotice(@"show notice at %@.", level);
        ChivoxLogInfo(@"show info at %@.", level);
        ChivoxLogDebug(@"show debug at %@", level);
        NSLog(@"");
    }
}

- (void)testLogFile {
    NSLog(@"==== testLogFile ========");
    NSString *tmpPath = NSTemporaryDirectory();
    NSString *logPath = [tmpPath stringByAppendingPathComponent:@"agn.log"];
    NSString *level = @"debug";
    ChivoxLogInit(level);
    ChivoxLogSetFile(logPath);
    ChivoxLogError(@"show error at %@.", level);
    ChivoxLogWarn(@"show warn at %@.", level);
    ChivoxLogNotice(@"show notice at %@.", level);
    ChivoxLogInfo(@"show info at %@.", level);
    ChivoxLogDebug(@"show debug at %@", level);
    
    NSLog(@"");
    
    NSString *logContent = [NSString stringWithContentsOfFile:logPath encoding:NSUTF8StringEncoding error:nil];
    NSLog(@"==== logfile content:\n%@", logContent);
}



@end
